PROGRAM VolumeLister;

{Cameron Birse, Macintosh Technical Support}

uses Memtypes,QuickDraw,OSIntf,ToolIntf;

 TYPE

    VolRec = RECORD
    VolRefNum : integer;
    DrvrRefNum : integer;
    DrvNum : integer;
    SCSIId  :   integer;
    VolName : Str255;
    end;
   

	VAR
 		err			: Integer;
   HPB         : HParamBlockRec;
   HPBPtr      : HParmBlkPtr;
   VolRefNum   : integer;
   VolRecs : array [0..9] of VolRec;
   volName : str255;
   index,Count,finalcount : integer;
   vcbQhdrPtr : QHdrPtr;
   a : char;
	
	{------------------------------------------------------------------------------------}
	
	 PROCEDURE Debugger; INLINE $A9FF;
 
	{------------------------------------------------------------------------------------}

  FUNCTION GetDrvNum (VRefNum : integer) :integer;
  
  TYPE
  VCBPtr = ^VCB;
  
  VAR
   vcbQhdrPtr : QHdrPtr;
   nextElem : QElemPtr;
  	flag : boolean;
  
  BEGIN
  	flag := false;
  	GetDrvNum := 0;
  vcbQhdrPtr := GetVCBQHdr;
	nextElem := vcbQhdrPtr^.qHead;
	while (nextElem <> nil) and (not flag) do
		begin
			if (VCBPtr(nextElem)^.vcbVRefNum = VRefNum) then
			begin
				GetDrvNum := VCBPtr(nextElem)^.vcbDrvNum;
				flag := true;
			end;
			nextElem := VCBPtr(nextElem)^.qLink;
		end;
  END;
  	
	{------------------------------------------------------------------------------------}
                                                
		BEGIN 							 {main PROGRAM}

  err := noerr;
  count := 1;
  Finalcount := 0;

   for index := 1 to 9 do
   begin
   if finalCount = 0 then
   begin
        HPBPtr := @HPB;
        HPB.ioCompletion := nil;
        HPB.ioNamePtr := @VolName;
        HPB.ioVRefNum := 0;
        HPB.ioVolIndex := count;
        err := PBHGetVInfo (HPBPtr, False);
        if err <> noerr then finalcount := count-1;
        VolRecs[byte(count)].VolRefNum := HPB.ioVRefNum;
        VolRecs[byte(count)].VolName := str255(HPB.ioNamePtr^);
        VolRecs[byte(count)].DrvrRefNum := HPB.ioVDRefNum;
        VolRecs[byte(count)].SCSIId := (-1*(HPB.ioVDRefNum+1))-32;
        VolRecs[byte(count)].DrvNum := GetDrvNum (HPB.ioVRefNum);
        count := count + 1;
   end;
   end;
   
   repeat
   count := 0;
   for index := 1 to finalcount do
   begin
    count := count + 1;
    if count = 5 then
    begin
        writeln ('press mouse button for more');
        writeln ('');
        repeat until button;
        count := 0;
    end;
    Writeln ('Volume Name : ',VolRecs[byte(index)].VolName);
    Writeln ('Volume RefNum : ',VolRecs[byte(index)].VolRefNum);
    Writeln ('Driver RefNum : ',VolRecs[byte(index)].DrvrRefNum);
    Writeln ('Drive Number : ',VolRecs[byte(index)].DrvNum);
    Case VolRecs[byte(index)].SCSIId of
    0..7 : Writeln ('SCSI Address : ',VolRecs[byte(index)].SCSIId);
    end; {case}
    Writeln ('');
   end;
   
   Writeln ('Do you wish to view again? (y/n)');
   readln (a);
   writeln ('');
   until a = 'n';
   
		END.